#include "camera.hpp"

#include <cfloat>

Camera::Camera()
{
	min.x = min.y = -FLT_MAX;
	max.x = max.y = FLT_MAX;
	vel.x = vel.y = 0;
}

Camera::~Camera()
{
}

void Camera::Size(float w, float h)
{
	size = Vec2f(w, h);
}

void Camera::Min(float left, float top)
{
	min = Vec2f(left, top);
}

void Camera::Max(float right, float bott)
{
	max = Vec2f(right - size.x, bott - size.y);
}

void Camera::Vel(float dx, float dy)
{
	vel = Vec2f(dx, dy);
}

void Camera::Pos(float x, float y)
{
	pos = Vec2f(x, y).LowerBound(min).UpperBound(max);
}

void Camera::Update()
{
	Pos(pos.x + vel.x, pos.y + vel.y);
}

#include "video.hpp"
#ifndef SILENT
#include "audio.hpp"
#endif

void Camera::Out(float upfrac)
{
	Vec2f lookpos (pos + vel * upfrac);
	lookpos = lookpos.LowerBound(min).UpperBound(max);
	Vid.Look(lookpos.x, lookpos.y);
#ifndef SILENT
	Vec2f listenpos (lookpos + HSize());
	Aud.Listen(listenpos.x, listenpos.y);
#endif
}

Camera Cam;
